using Newtonsoft.Json;

namespace FeishuWorkflowService.Models
{

    /// <summary>
    /// 触发工作流请求
    /// </summary>
    public class TriggerWorkflowRequest
    {
        /// <summary>
        /// 审批定义Code
        /// </summary>
        public string ApprovalCode { get; set; } = string.Empty;

        /// <summary>
        /// 操作人ID
        /// </summary>
        public string OperatorId { get; set; } = string.Empty;

        /// <summary>
        /// 审批人用户ID列表
        /// </summary>
        public Dictionary<string, List<string>> ApproverUserIds { get; set; } = new Dictionary<string, List<string>>();

        /// <summary>
        /// 表单数据
        /// </summary>
        public Dictionary<string, object>? FormData { get; set; } 
    }

    /// <summary>
    /// 工作流回调数据
    /// </summary>
    public class WorkflowCallbackData
    {
        /// <summary>
        /// 回调类型
        /// </summary>
        [JsonProperty("type")]
        public string Type { get; set; } = string.Empty;

        /// <summary>
        /// 回调事件
        /// </summary>
        [JsonProperty("event")]
        public WorkflowCallbackEvent Event { get; set; } = new WorkflowCallbackEvent();

        /// <summary>
        /// 回调Token
        /// </summary>
        [JsonProperty("token")]
        public string Token { get; set; } = string.Empty;

        /// <summary>
        /// 回调时间戳
        /// </summary>
        [JsonProperty("ts")]
        public string Timestamp { get; set; } = string.Empty;

        /// <summary>
        /// 回调UUID
        /// </summary>
        [JsonProperty("uuid")]
        public string Uuid { get; set; } = string.Empty;
    }

    /// <summary>
    /// 工作流回调事件
    /// </summary>
    public class WorkflowCallbackEvent
    {
        /// <summary>
        /// 实例ID
        /// </summary>
        [JsonProperty("instance_id")]
        public string? InstanceId { get; set; }

        /// <summary>
        /// 审批状态
        /// </summary>
        [JsonProperty("approval_status")]
        public string? ApprovalStatus { get; set; }

        /// <summary>
        /// 审批定义Code
        /// </summary>
        [JsonProperty("approval_code")]
        public string? ApprovalCode { get; set; }

        /// <summary>
        /// 表单数据
        /// </summary>
        [JsonProperty("form")]
        public Dictionary<string, object>? Form { get; set; }
    }

    /// <summary>
    /// API响应
    /// </summary>
    public class ApiResponse<T>
    {
        /// <summary>
        /// 状态码
        /// </summary>
        public int Code { get; set; }

        /// <summary>
        /// 消息
        /// </summary>
        public string Message { get; set; } = string.Empty;

        /// <summary>
        /// 数据
        /// </summary>
        public T? Data { get; set; }

        /// <summary>
        /// 成功响应
        /// </summary>
        public static ApiResponse<T> Success(T data, string message = "操作成功")
        {
            return new ApiResponse<T>
            {
                Code = 0,
                Message = message,
                Data = data
            };
        }

        /// <summary>
        /// 失败响应
        /// </summary>
        public static ApiResponse<T> Fail(string message, int code = -1)
        {
            return new ApiResponse<T>
            {
                Code = code,
                Message = message,
                Data = default
            };
        }
    }
}